<?PHP
    $pp_path="..";
    include_once ($pp_path."/common.php");
?>
<!DOCTYPE HTML>
<html>
<head>
    <link href="/css/jquery-ui-1.10.2.custom.min.css" rel="stylesheet" />
    <style>
        * { font-family: "Dotum", "Dotumche"; font-size: 12px; }
        html { height: 100%; }
        body { padding: 0px; margin: 0px; height: 100%; }

        #gcm { width: 100%; }
        #gcm table { width: 100%; padding: 0px; border-collapse: collapse; border-top: 2px solid #EEEEEE; border-bottom: 2px solid #EEEEEE; }
        #gcm th { height: 30px; width: 200px; border-top: 1px solid #EEEEEE; border-bottom: 1px solid #EEEEEE; color: #CC0000; }
        #gcm td { height: 30px; border-top: 1px solid #EEEEEE; border-bottom: 1px solid #EEEEEE; }
        #gcm #btn_wrap { width: 100%; text-align: center; padding: 10px 0px; }

        .text { width: 95%; }
        .textarea { width: 95%; height: 100px; resize: none; margin: 5px 0px; }
    </style>
</head>
<body>
    <div id="gcm">
        <form id="gcmFrm" name="gcmFrm">
        <input type="hidden" name="p_code" id="p_code" value="<?PHP echo $p_code; ?>" />
        <table>
        <tr>
            <th>SENDER</th>
            <td><input type="text" id="gcm_sender" name="gcm_sender" class="text" /></td>
        </tr>
        <tr>
            <th>RECEIVER</th>
            <td><input type="text" id="gcm_receiver" name="gcm_receiver" class="text" /></td>
        </tr>
        <tr>
            <th>SUBJECT</th>
            <td><input type="text" id="gcm_subject" name="gcm_subject" class="text" /></td>
        </tr>
        <tr>
            <th>SEND DATE</th>
            <td>
                <input type="radio" name="gcm_send" value="Y" checked="checked" /> NOW
                <input type="radio" name="gcm_send" value="N" /> RESERVATION
                <div id="reserve_date" style="display: none;">(
                    <select id="reserve_year" name="reserve_year">
                    <?PHP for ($i=date("Y", time()); $i<date("Y", time())+12; $i++) { ?>
                        <option value="<?PHP echo sprintf("%02d", $i)?>"><?PHP echo sprintf("%02d", $i)?></option>
                    <?PHP } ?>
                    </select> Year
                    <select id="reserve_month" name="reserve_month">
                    <?PHP for ($i=1; $i<13; $i++) { ?>
                        <option value="<?PHP echo sprintf("%02d", $i)?>"<?PHP if ($i==date("m", time())) { echo " selected=\"selected\""; }?>><?PHP echo sprintf("%02d", $i)?></option>
                    <?PHP } ?>
                    </select> Month
                    <select id="reserve_day" name="reserve_day">
                    <?PHP for ($i=1; $i<32; $i++) { ?>
                        <option value="<?PHP echo sprintf("%02d", $i)?>"<?PHP if ($i==date("d", time())) { echo " selected=\"selected\""; }?>><?PHP echo sprintf("%02d", $i)?></option>
                    <?PHP } ?>
                    </select> Days
                    <select id="reserve_hour" name="reserve_hour">
                    <?PHP for ($i=1; $i<25; $i++) { ?>
                        <option value="<?PHP echo sprintf("%02d", $i)?>"<?PHP if ($i==date("H", time())) { echo " selected=\"selected\""; }?>><?PHP echo sprintf("%02d", $i)?></option>
                    <?PHP } ?>
                    </select> Hour )
                </div>
            </td>
        </tr>
        <tr>
            <th>CONTENTS</th>
            <td><textarea id="gcm_contents" name="gcm_contents" class="textarea"></textarea></td>
        </tr>
        </table>
        </form>
        <div id="btn_wrap">
            <a id="btn_send" class="btn">SEND</a>
            <a id="btn_cancel" class="btn">CANCEL</a>
        </div>
    </div>
    <script src="/script/jquery-1.9.1.js"></script>
    <script src="/script/jquery-ui-1.10.2.custom.min.js"></script>
    <script>
    var sender=["Choi Chul Ki", "Kim Jung Oh", "Yu Bo Sun", "Lim Hee Suk", "Park Il Kwon", "Kim Yu Hyeon"];
    $(function(){
        $(".btn").button();
        $("#gcm_sender").autocomplete({
            source: sender
        });
        $("input[name=gcm_send]").change(function(){
            if ($("input[name=gcm_send]:checked").val()=="N")
                $("#reserve_date").css("display", "inline");
            else
                $("#reserve_date").css("display", "none");
        });
        $("#btn_send").click(function(){
            if (!$.trim($("#gcm_sender").val())) {
                alert("Please Insert Send Name");
                $("#gcm_sender").focus();
                return false;
            }

            if (!$.trim($("#gcm_subject").val())) {
                alert("Please Insert Subject");
                $("#gcm_subject").focus();
                return false;
            }

            var date=$("#reserve_year option:selected").val()+$("#reserve_month option:selected").val()+$("#reserve_day option:selected").val()+$("#reserve_hour option:selected").val();
            if ($("input[name=gcm_send]:checked").val()=="N" && date<<?PHP echo date("YmdH", time()); ?>) {
                alert("Please Selectd Reserve Date");
                return false;
            }

            if (!$.trim($("#gcm_contents").val())) {
                alert("Please Insert Contents");
                $("#gcm_contents").focus();
                return false;
            }

            $.ajax({
                url:"/proc/send.proc.php",
                type:"post",
                data:$("#gcmFrm").serialize(),
                dataType:"json",
                success: function(d) {
                    if (d.result) {
                        alert("Success Send\nMove Result Page");
                        window.location.replace("/include/result.inc.php");
                    } else {
                        alert("!!Error!!");
                        return false;
                    }
                }
            });
        });
        $("#btn_cancel").click(function(){
            $("#gcmFrm")[0].reset();
        });
    });
    </script>
</body>
</html>